using Gtk;
using System;
using System.Collections;
using System.Reflection;
using NHibernate;
using Serpis;
using PVenta;

public partial class MainWindow : Gtk.Window
{
	public MainWindow () : base(Gtk.WindowType.Toplevel)
	{
		Build ();
		refreshActions();
		
		notebook.SwitchPage += delegate 
		{
			refreshActions();
		};
		
		notebook.PageRemoved += delegate 
		{
			refreshActions();
		};
		
		newAction.Activated += delegate 
		{
			currentListView.New();
		};
		
		editAction.Activated += delegate 
		{
			currentListView.Edit();
		};
		
		deleteAction.Activated += delegate 
		{
			currentListView.Delete();
		};
		
		ArticuloAction.Activated += delegate 
		{
			ArticuloListView articuloListView= new ArticuloListView();
			notebook.AddTab(articuloListView);
			articuloListView.Changed += delegate 
			{
				refreshActions();
			};
		};
	}
	
	
	private void refreshActions()
	{
		IListView listView= currentListView;
		newAction.Sensitive= listView != null;
		editAction.Sensitive= listView != null && listView.HasSelected;
		deleteAction.Sensitive= listView != null && listView.HasSelected;		
	}
	
	private IListView currentListView 
	{
		get {return notebook.CurrentPageWidget as IListView;}
	}
	
	protected void OnDeleteEvent (object sender, DeleteEventArgs a)
	{
		Application.Quit ();
		a.RetVal = true;
	}
}
